<?php 
class Search extends CI_Controller {
	function __construct()
	{
		parent::__construct();
		$this->load->model('Search_model');
		$this->load->model('Company_model');
	}
	
	function index($query=null)
	{		
		print_r($this->Search_model->get_posts($query,10,1));
	}
	
	function go()
	{
		$q = base64_encode($this->input->post('q'));
		//$q = base64_encode($q);
		if ($q[strlen($q)-1]=='=') $q = substr($q,0,strlen($q)-2);
		//echo $q;
		redirect('search/find/'.$q.'/1');
	}
	
	function find()
	{
		$query = $this->input->post('q');
		$data = array();
		$data = array('listings'=>$this->Search_model->get_posts($query,10,1));

		$this->load->library('form');
		$this->form->open('search/find', 'search_form')
					->fieldset('Search')
					->text('q', '', 'max_length[40]',$query)
					->submit('Submit');
					//->nobr();
		$data['form'] = $this->form->get();
		$data['errors'] = $this->form->errors;
		
		$this->load->view('search/header');
		$this->load->view('search/form',$data);
		$this->load->view('search/results',$data);
		$this->load->view('search/footer');
	}
}

?>